home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / IRIT_SM.H < prev    next >
C/C++ Source or Header  |  1992-01-31  |  6KB  |  191 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, Jan. 1992   *
  5. ******************************************************************************
  6. * Main definition Header file  for Irit - the 3d polygonal solid modeller.   *
  7. *****************************************************************************/
  8.  
  9. #ifndef    IRIT_SM_H
  10. #define    IRIT_SM_H
  11.  
  12. /* Note program version should also be updated in *.c modules, in few        */
  13. /* places, as some system can not chain strings in the pre-processor level.  */
  14. #define  VERSION    "Version 3.0"             /* Program version. */
  15.  
  16. #include <string.h>
  17. #ifdef __hpux
  18. extern char *strdup();
  19. #endif /* __hpux */
  20.  
  21. #ifdef __MSDOS__
  22. #include <mem.h>                        /* Used for memcpy rtns. */
  23. #endif /* __MSDOS__ */
  24.  
  25. #ifndef    NULL
  26. #define    NULL    0
  27. #endif /* NULL */
  28.  
  29. #ifndef    TRUE
  30. #define    TRUE    1
  31. #define    FALSE    0
  32. #endif /* TRUE */
  33.  
  34. #ifdef VoidPtr
  35. #undef VoidPtr
  36. #endif /* VoidPtr */
  37.  
  38. #ifdef NO_VOID_PTR
  39. #define VoidPtr        char *
  40. #else
  41. #define VoidPtr        void *
  42. #endif /* NO_VOID_PTR */
  43.  
  44. #if !defined(FLOAT) && !defined(DOUBLE)
  45. #ifdef __MSDOS__
  46. #define FLOAT
  47. typedef    float        RealType;        /* On IBMPC to reserve memory... */
  48. #else
  49. #define DOUBLE
  50. typedef    double        RealType;
  51. #endif /* __MSDOS__ */
  52. #endif /* !FLOAT && !DOUBLE */
  53.  
  54. typedef    unsigned char    ByteType;
  55.  
  56. typedef    RealType    PointType[3];    /* For X, Y, Z coordinates of point. */
  57. typedef RealType    VectorType[3];
  58. typedef RealType    NormalType[3];        /* Unit normalized normal coeff. */
  59. typedef RealType    PlaneType[4];            /* Plane equation coeff. */
  60. typedef RealType    MatrixType[4][4];       /* Homogeneous transform. */
  61.  
  62. #define EPSILON        1e-5
  63. #define INFINITY    1e6
  64.  
  65. #ifndef M_PI
  66. #define M_PI    3.14159265358979323846
  67. #endif /* M_PI */
  68.  
  69. #define LINE_LEN_LONG    256           /* Lines read from stdin/files... */
  70. #define LINE_LEN    81           /* Lines read from stdin/files... */
  71. #define LINE_LEN_SHORT    31           /* Lines read from stdin/files... */
  72. #define OBJ_NAME_LEN    11                /* Names of objects. */
  73. #define FILE_NAME_LEN    13           /* Name (8) + Type (3) + Dot (1). */
  74. #define PATH_NAME_LEN    80                      /* Name with full Path */
  75.  
  76. /* Follows by general purpose helpfull macros: */
  77. #ifndef MIN
  78. #define MIN(x, y)        ((x) > (y) ? (y) : (x))
  79. #endif /* MIN */
  80. #ifndef MAX
  81. #define MAX(x, y)        ((x) > (y) ? (x) : (y))
  82. #endif /* MAX */
  83. #define BOUND(x, Min, Max)    (MAX(MIN(x, Max), Min))
  84.  
  85. #define ABS(x)            ((x) > 0 ? (x) : (-(x)))
  86. #define SQR(x)            ((x) * (x))
  87. #define SIGN(x)            ((x) > 0 ? 1 : ((x) < 0 ? -1 : 0))
  88.  
  89. #define SWAP(type, x, y)    { type temp = (x); (x) = (y); (y) = temp; }
  90.  
  91. #define REAL_TO_INT(R)        ((int) (R + 0.5))
  92. #define REAL_PTR_TO_INT(R)    ((int) ((*R) + 0.5))
  93.  
  94. #define APX_EQ(x, y)        (ABS(x - y) < EPSILON)
  95. #define PT_EQ(Pt1, Pt2)        (APX_EQ(Pt1[0], Pt2[0]) && \
  96.                  APX_EQ(Pt1[1], Pt2[1]) && \
  97.                  APX_EQ(Pt1[2], Pt2[2]))
  98.  
  99. #define PT_CLEAR(Pt)        { Pt[0] = Pt[1] = Pt[2] = 0.0; }
  100.  
  101. #define PT_SCALE(Pt, Scalar)    { Pt[0] *= Scalar; \
  102.                   Pt[1] *= Scalar; \
  103.                   Pt[2] *= Scalar; \
  104.                     }
  105.  
  106. /* The memcpy is sometimes defined to get (char *) pointers and sometimes     */
  107. /* (void *) pointers. To be compatible with both it is coerced to (char *).   */
  108. #define PT_COPY(PtDest, PtSrc)      memcpy((char *) (PtDest), (char *) (PtSrc), \
  109.                             3 * sizeof(RealType))
  110. #define PLANE_COPY(PlDest, PlSrc) memcpy((char *) (PlDest), (char *) (PlSrc), \
  111.                             4 * sizeof(RealType))
  112. #define MAT_COPY(Dest, Src)      memcpy((char *) (Dest), (char *) (Src), \
  113.                             16 * sizeof(RealType))
  114. #define GEN_COPY(Dest, Src, Size) memcpy((char *) (Dest), (char *) (Src), Size)
  115. #define ZAP_MEM(Dest, Size)      memset((char *) (Dest), 0, Size);
  116.  
  117.  
  118. #define PT_LENGTH(Pt)        sqrt(SQR(Pt[0]) + SQR(Pt[1]) + SQR(Pt[2]))
  119.  
  120. #define PT_NORMALIZE(Pt)    { RealType Size = PT_LENGTH(Pt); \
  121.                   Pt[0] /= Size; \
  122.                   Pt[1] /= Size; \
  123.                   Pt[2] /= Size; \
  124.                 }
  125.  
  126. #define PT_BLEND(Res, Pt1, Pt2, t) \
  127.                 { Res[0] = Pt1[0] * t + Pt2[0] * (1 - t); \
  128.                   Res[1] = Pt1[1] * t + Pt2[1] * (1 - t); \
  129.                   Res[2] = Pt1[2] * t + Pt2[2] * (1 - t); \
  130.                     }
  131.  
  132. #define PT_ADD(Res, Pt1, Pt2)    { Res[0] = Pt1[0] + Pt2[0]; \
  133.                   Res[1] = Pt1[1] + Pt2[1]; \
  134.                   Res[2] = Pt1[2] + Pt2[2]; \
  135.                     }
  136.  
  137. #define PT_SUB(Res, Pt1, Pt2)    { Res[0] = Pt1[0] - Pt2[0]; \
  138.                   Res[1] = Pt1[1] - Pt2[1]; \
  139.                   Res[2] = Pt1[2] - Pt2[2]; \
  140.                 }
  141.  
  142. #define PT_SWAP(Pt1, Pt2)    { SWAP(RealType, Pt1[0], Pt2[0]); \
  143.                   SWAP(RealType, Pt1[1], Pt2[1]); \
  144.                   SWAP(RealType, Pt1[2], Pt2[2]); \
  145.                 }
  146.  
  147. #define DOT_PROD(Pt1, Pt2)    (Pt1[0] * Pt2[0] + \
  148.                  Pt1[1] * Pt2[1] + \
  149.                  Pt1[2] * Pt2[2])
  150.  
  151. #define CROSS_PROD(PtRes, Pt1, Pt2) \
  152.                 { PtRes[0] = Pt1[1] * Pt2[2] - Pt1[2] * Pt2[1]; \
  153.                   PtRes[1] = Pt1[2] * Pt2[0] - Pt1[0] * Pt2[2]; \
  154.                   PtRes[2] = Pt1[0] * Pt2[1] - Pt1[1] * Pt2[0]; }
  155.  
  156. #define DEG2RAD(Deg)        ((Deg) * M_PI / 180.0)
  157. #define RAD2DEG(Rad)        ((Rad) * 180.0 / M_PI)
  158.  
  159. #if defined(_AIX) || defined(DJGCC) || defined(__MSDOS__)
  160. #include <stdlib.h>
  161. #else
  162. VoidPtr malloc(unsigned int Size);
  163. void free(char *p);
  164. char *getenv(char *Name);
  165. int atoi(char *str);
  166. #endif /* _AIX || DJGCC || __MSDOS__ */
  167.  
  168. #ifndef __MSDOS__
  169. void movmem(VoidPtr Src, VoidPtr Dest, int Len);
  170. char *searchpath(char *Name);
  171. #endif /* __MSDOS__ */
  172.  
  173. #ifdef STRICMP
  174. int strnicmp(char *s1, char *s2, int n);
  175. int stricmp(char *s1, char *s2);
  176. #endif /* STRICMP */
  177.  
  178. #ifdef STRSTR
  179. char *strstr(char *s, char *Pattern);
  180. #endif /* STRSTR */
  181.  
  182. #ifdef STRDUP
  183. char *strdup(char *s);
  184. #endif /* STRDUP */
  185.  
  186. #ifdef GETCWD
  187. char *getcwd(char *s, int Len);
  188. #endif /* GETCWD */
  189.  
  190. #endif    /* IRIT_SM_H */
  191.